import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: '首页',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/import',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/import')
      }
    ]
  },
  {
    path: '/users',
    component: Layout,
    hidden: true,
    meta: 'user',
    children: [
      {
        path: '/users/approvals',
        component: () => import('@/views/users/approvals'),
        name: 'usersApprovals',
        hidden: true,
        meta: {
          title: '用户'
        }
      },
      {
        path: '/users/info',
        component: () => import('@/views/users/info'),
        name: 'myInfo',
        hidden: true,
        meta: {
          title: '我的信息'
        }
      }
    ]
  }

  // {
  //   path: '/setting',
  //   meta: 'settings',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/setting'),
  //       meta: { title: '公司设置', icon: 'setting' }
  //     }
  //   ]
  // },
  // {
  //   path: '/employees',
  //   meta: 'employees',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/employees'),
  //       meta: { title: '员工', icon: 'people' }
  //     },
  //     {
  //       path: 'detail/:id', // query传参 动态路由传参
  //       component: () => import('@/views/employees/detail'),
  //       hidden: true, // 不在左侧菜单显示
  //       meta: {
  //         title: '员工详情' // 标记当前路由规则的中文名称 后续在做左侧菜单时 使用
  //       }
  //     },
  //     {
  //       path: 'print/:id', // 二级默认路由
  //       component: () => import('@/views/employees/print'), // 按需加载
  //       hidden: true,
  //       meta: {
  //         title: '打印', // 标记当前路由规则的中文名称 后续在做左侧菜单时 使用
  //         icon: 'people'
  //       }
  //     }
  //   ]
  // },
  // {
  //   path: '/permission',
  //   meta: 'permissions',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/permission'),
  //       meta: { title: '权限管理', icon: 'lock' }
  //     }
  //   ]
  // },
  // {
  //   path: '/salarys',
  //   meta: 'salarys',
  //   component: Layout,
  //   children: [
  //     {
  //       path: '',
  //       component: () => import('@/views/salarys'),
  //       meta: { title: '工资', icon: 'money' }
  //     }
  //   ]
  // }
]
// 引入多个模块的规则
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'

// 动态路由
export const asyncRoutes = [
  approvalsRouter,
  departmentsRouter,
  employeesRouter,
  permissionRouter,
  attendancesRouter,
  salarysRouter,
  settingRouter,
  socialRouter
]

const createRouter = () =>
  new Router({
    mode: 'history',
    base: '/hr/',
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes]
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
